import http from '@/plugins/axios'

/**
 *
 * @param data 查询投诉记录
 * @returns
 */
export function getComplaintSuggestionList(data) {
    let res = http({
        method: 'POST',
        url: '/new/ykf/customer/complaint/getComplaintSuggestionsList',
        data
    })
    console.log(res);
    return res;
}

/**
 *
 * @param data 新增投诉记录
 * @returns
 */
export function addComplaintSuggestion(data) {
    return http({
        method: 'POST',
        url: '/new/ykf/customer/complaint/addComplaintSuggestion',
        data
    })
}

/**
 *
 * @param data 编辑投诉记录
 * @returns
 */
export function editComplaintSuggestion(data) {
    return http({
        method: 'POST',
        url: '/new/ykf/customer/complaint/editComplaintSuggestion',
        data
    })
}

/**
 * 查询业务对接人
 * @returns
 */
export function getUserList(data) {
    return http({
        method: 'POST',
        url: '/new/ykf/customer/getUserListByRoleId',
        data
    })
}
/**
 * 查询问题分布二
 * @returns
 */
export function getdictIdList(data) {
    return http({
        method: 'POST',
        url: '/new/ykf/customer/complaint/parentId',
        data
    })

}

/**
 * 添加投诉建议子表
 */
export function addSuggestionDetailList(data) {
    let res = http({
        method: 'POST',
        url: '/new/ykf/customer/complaintDetail/addComplaintSuggestionDetail',
        data
    })
    return res;
}

/**
 * 编辑投诉建议子表
 */
export function editSuggestionDetailList(data) {
    let res = http({
        method: 'POST',
        url: '/new/ykf/customer/complaintDetail/editComplaintSuggestionDetail',
        data
    })
    return res;
}

/**
 * 文件上传到后台
 */
export function postUploadFile(formData: Record<string, any>, files: File[]) {
    const uploadData = new FormData();

    // 添加表单字段
    for (const key in formData) {
        if (formData.hasOwnProperty(key)) {
            uploadData.append(key, formData[key]);
        }
    }
    // 添加多个文件
    files.forEach(file => {
        uploadData.append('files', file);
    });

    // 打印 FormData 内容（用于调试）
    for (let [key, value] of uploadData.entries()) {
        console.log(`${key}:`, value)
    }

    return http({
        method: 'POST',
        url: '/new/ykf/customer/complaint/fileUpload',
        data: uploadData,
    });
}
